#include <iostream>
#include <string>
#include <memory>
#include "Reactor.hpp"
#include "Socket.hpp"
#include "Accepter.hpp"
using namespace std;
using namespace Net_Work;
const int default_backlog = 32;


int main(int argc, char* args[]) {
    if (argc != 2) {
        cout << "Usage:\n\r" << args[0] << "local_port\n" << endl;
        return 0;
    }
    uint16_t port = stoi(args[1]);
    // 创建监听套接字
    unique_ptr<Socket> listensocket(new TcpSocket());
    listensocket->BuildListenSocketMethod(port, default_backlog);
    // 创建Reactor对象
    unique_ptr<Reactor> reactor(new Reactor());
    // 创建监听Connection
    Connection* listen_conn = ConnFactory::BuildListenConnection(listensocket->GetSockFd(), Accepter::Accept, EPOLLIN | EPOLLET, reactor.get());
    // 添加到_connections中
    reactor->AddConnection(listen_conn);
    reactor->Dispatch();
    return 0;
}
